<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <input type="text" placeholder="员工姓名" v-model="emp.name">
  <input type="text" placeholder="员工工资" v-model="emp.salary">
  <input type="text" placeholder="员工工作" v-model="emp.job">
  <input type="button" value="添加" @click="f()">
  <table border="1">
    <caption>员工列表</caption>
    <tr>
      <th>编号</th><th>姓名</th>
      <th>工资</th><th>工作</th><th>操作</th>
    </tr>
    <tr v-for="(emp,i) in arr">
      <td>{{i+1}}</td><td>{{emp.name}}</td>
      <td>{{emp.salary}}</td><td>{{emp.job}}</td>
      <td><input type="button" value="删除" @click="del(i)"></td>
    </tr>
  </table>
</div>
<script src="js/vue.min.js"></script>
<script>
  let v = new Vue({
    el:"body>div",
    data:{
      arr:[{name:"刘备",salary:3000,job:"销售"},
        {name:"关羽",salary:4000,job:"人事"},
        {name:"张飞",salary:5000,job:"程序员"}],
      emp:{name:"",salary:"",job:""}
    },
    methods:{
      f(){
        //往arr数组里面添加一个新的对象, 对象的数据来自于双向绑定的emp对象
        v.arr.push({name:v.emp.name,salary:v.emp.salary,job:v.emp.job});
      },
      del(i){
        //从数组中删除元素 splice(下标,数量)
        v.arr.splice(i,1);
      }
    }
  })
</script>
</body>
</html>